package util
{
	import flash3.framework.IUpdate;
	import flash3.framework.ListManager;
	import flash3.framework.UpdateManager;
	
	public class HandleQueue extends ListManager implements IUpdate
	{
		private var time:Number = 0;
		private var finish:Boolean = true;
		private var stop:Boolean = true;
		
		public function HandleQueue()
		{
			UpdateManager.i.add(this);
		}
		
		public function start():void
		{
			reset();
			stop = false;
			finish = false;
		}
		
		public function update(lastTime:int):void
		{
			if(stop || finish) return;
			
			for(var i:uint = 0;i < list.length; i++)
			{
				if(time >= list[i].delay)
				{
					list[i].handle.apply(null, list[i].parm);
					list.splice(i, 1);
				}
			}
			
			finish = list.length == 0;
			time += lastTime;
		}
		
		public function reset():void
		{
			time = 0;
		}
	}
}